<template>
  <div>
    {{className}} <el-button type="text" size="small" @click="deCompile" icon="el-icon-refresh"/>
    <monaco-editor ref="codeEditor" language="java" :code="compileResult"/>
  </div>
</template>

<script>
import core from '@/api/core'

import MonacoEditor from '@/views/components/MonacoEditor'

export default {
  name: 'DeCompile',
  components: {MonacoEditor},
  props: {
    classloaderName: String,
    className: String
  },
  data(){
    return {
      compileResult: null
    }
  },
  mounted() {
    this.deCompile()
  },
  methods: {
    deCompile(){
      if (this.className){
        core.deCompileClass(this.classloaderName,this.className).then(res => {
          this.compileResult = res.data
        })
      }
    }
  },
  watch: {
    className: {
      handler(){
        this.deCompile()
      }
    }
  }
}
</script>

<style scoped>
.editor{
  height: 75vh;
}
</style>
